<%@ page import="com.news.model.CreatePage" %>
<%@ page import="com.news.db.OpDB" %>
<%@ page import="com.news.model.News" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>内容显示区</title>
    <style type="text/css">
      #table {
        border: 1px red solid;
      }

      #table td {
        border: 1px blue solid;
        text-align: center;
      }

      #table th {
        background-color: maroon;
      }
      .over {
        background-color: aqua;
      }
    </style>

    <script type="text/javascript">
      // 动态事件注册，先要把这个文档加载完成的事件先添加上
      window.onload = function() {
        // 再通过tr标签查找到所有的行标签对象
        var trs = document.getElementById("table").getElementsByTagName("tr");
        // 遍历每一个行标签对象，来设置它的class属性值
        for (var i = 1; i < trs.length; i++){
          // 定义一个变量来保存修改这个class属性值之前的旧的样式名
          var oldClass = "";
          // 当鼠标移进去的时候的事件
          trs[i].onmouseover = function(){
            oldClass = this.className;
            this.className = "over";
          }
          // 当鼠标移出的时候的事件
          trs[i].onmouseout = function() {
            this.className = oldClass;
          }
        }
      }
    </script>
    <script>
      function deleteN(id) {
        if (confirm("您确定要删除吗？")){
          location.href="http://localhost:8080/news_war_exploded/delN?id="+id;
        }

      }
    </script>
  </head>
  <body>
    <table border="0" width="700" height="500" cellspacing="0" cellpadding="0" align="right">
      <tr>
        <td align="center">
          <%
            String showpage = request.getParameter("showpage");
            if(showpage == null || showpage.equals("")){showpage="1";}
            String sqlAll = "select * from tb_info order by info_date desc";
            String gowhich = "admin/IndexTemp.jsp";
            OpDB opdb = new OpDB();
            CreatePage cp = opdb.OpCreatePage(sqlAll, null, 5, gowhich, showpage);
            String sqlsub = "";
            int top = (cp.getCurrentP()-1)*3;
            if(cp.getCurrentP() == 1){
              sqlsub = "select TOP 5 * from tb_info order by info_date desc";
            }else{
              sqlsub = "select TOP 5 * from tb_info where id > (select MAX(id) from (select TOP "+top+"(id) from tb_info order by id) as maxid)";
            }
            ArrayList<News> list = opdb.OpGetNewsAll(sqlsub);
            if(list != null && list.size() > 0){
          %>
          <table border="1" cellpadding="0" cellspacing="0" width="700" height="480" style="text-align: center" id="table">
            <tr>
              <td>新闻类别</td>
              <td>新闻标题</td>
              <td>发布时间</td>
              <td>删除/修改</td>
            </tr>
            <%
              for(int i=0; i<list.size(); i++){
                News n = list.get(i);
            %>
            <tr>
              <td><%=n.getTypeName()%></td>
              <td><a href="view/news_info.jsp?id=<%=n.getId()%>"><%=n.getInfo_title() %></a></td>
              <td><%=n.getInfo_date() %></td>
              <td><a href="javascript:deleteN(<%=n.getId() %>);">删除</a>/<a href="http://localhost:8080/news_war_exploded/findidn?id=<%=n.getId()%>">修改</a></td>
            </tr>
            <%
              }
            %>
            <tr>
              <td colspan="2"><%=cp.getPageInfo() %></td>
              <td colspan="2"><%=cp.getPageLink() %></td>
            </tr>
            <%
              }
            %>
          </table>
        </td>
      </tr>
    </table>
  </body>
</html>